<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	  xmlns:h="http://java.sun.com/jsf/html"
	  xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
	  xmlns:p="http://primefaces.prime.com.tr/ui">
<ui:composition template="/templates/cadastro.xhtml">
	
	<ui:define name="corpo">
		<h:form id="listagem">
			<p:dataTable var="artigo" dynamic="true" lazy="true"
			             value="#{artigoHandler.artigos}" 
						 selectionMode="single"
						 rows="7" 
						 paginator="true"
						 style="width: 100%"
			             id= "artigos" 
						 border="1">
				<p:column>
					<f:facet name="header">Id</f:facet>
					<h:outputText value="#{artigo.id}"> </h:outputText>
				</p:column>
				<p:column>
					<f:facet name="header">Artigo</f:facet>
					<h:outputText value="#{artigo.descricao}"> </h:outputText>
				</p:column>
				<p:column>
					<f:facet name="header">Operação</f:facet>
					<h:commandLink actionListener="#{artigoHandler.editar}">Editar
						<f:param id="editarartigoParam" name="id" value="#{artigo}" />
						<f:ajax execute="@this" render=":edicao" />
					</h:commandLink>
				</p:column>
				<p:column>
					<f:facet name="header">Operação</f:facet>
					<h:commandLink actionListener="#{artigoHandler.excluir}">Excluir
						<f:param id="excluirartigoParam" name="id1" value="#{artigo.id}" />
						<f:ajax execute="@this" render=":listagem" />
						<f:ajax execute="@this" render=":edicao" />
					</h:commandLink>
				</p:column>
			</p:dataTable>
		</h:form>
		<br />
		
		<h:form id="edicao">
		<h:outputText rendered="#{artigoHandler.emNavegacao}">
			<h:commandButton action="#{artigoHandler.novo}" value="Novo Artigo" />
		</h:outputText>
		<h:outputText rendered="#{artigoHandler.emEdicao}">
			<h:panelGrid columns="2" >
				
				<h:outputLabel value="Área de Atuação:" for="descricao" />
				<h:inputText id="descricao" label="descricao"
					value="#{artigoHandler.artigo.descricao}" required="true" />
				
				<h:outputText value="&nbsp;" />
				<h:outputText value="&nbsp;" />
				
				<h:outputText value="&nbsp;" />
				<h:commandButton action="#{artigoHandler.salvar}" value="Salvar Dados" />
				
			</h:panelGrid>
			</h:outputText>
			<h:messages style="color: red" />
		</h:form>
	</ui:define>
</ui:composition>
</html>
